<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // var a = 10;



        // let a = 10;
        // console.log(a);

        /*
                console.log(b); //undefined   变量声明但未定义   var 全局变量  变量声明可以提升
                var b = 20;
        */


        /*
                // 1 let 声明的变量 不会提升
                console.log(c);
                let c = 30;

        */



        /*
        let 特点
        1 let 声明的变量 不会提升
        2 let声明的变量有块级作用域 {}
        3 暂时性死区
        */




        /*
              
                var d = 10;
                if (true) {
                    console.log(d); //10

                    let f = 20;
                    console.log(f); //20  
                }
                console.log(f); //f is not defined

        */



        /*
                // 块级作用域 {}

                let d = 10;
                if (true) {
                    console.log(d); //10

                    let f = 20;
                    console.log(f); //20  
                }
                console.log(f); //f is not defined
        */




        /*

                {
                    let aa = 100;
                }
                console.log(aa); //aa is not defined


                */




        /*
                //  暂时性死区
                var msg = 'zs';
                if (true) {
                    let msg = 'lisi';
                    console.log(msg); //lisi
                }
                console.log(msg); //zs

        */


        var tmp = 123;
        if (true) {
            tmp = 'abc'; //报错 connot access 'tmp'
            let tmp;
            console.log(tmp);
        }
        console.log(tmp);
    </script>
</body>

</html>